package edu.zut.cs.software.perfect.manager.web.spring.controller;
/**
 * @ClassName AdministratorController

 * @Description TODO
 * @Author wst
 * @Date 2020年5月30日 上午12:23:25
 * @Version 1.0
 */

import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;

import edu.zut.cs.software.perfect.base.web.spring.controller.GenericController;
import edu.zut.cs.software.perfect.course.domain.CourseCategory;
import edu.zut.cs.software.perfect.manage.domain.Administrator;
import edu.zut.cs.software.perfect.manage.service.AdministratorManager;
import edu.zut.cs.software.perfect.process.domain.CourseProcess;



@RestController
@RequestMapping("/administrator")
public class AdministratorController extends GenericController<Administrator,Long,AdministratorManager>{
	
	AdministratorManager administratorManager;

	@Autowired
	public void setAdministratorManager(AdministratorManager administratorManager) {
		this.administratorManager = administratorManager;
		this.manager=administratorManager;
	}
	
	
	@RequestMapping(method = RequestMethod.GET, value = "/index.html")
	public String index() {
		String result = "/administrator/index";
		return result;
	}
	
//	@RequestMapping("getAdministratorById")
//	@ResponseBody
//	public Administrator getAdministratorById(Long id) {
//		return administratorManager.getAdministratorById(id);
//	}

//	@RequestMapping("findById")
//	@ResponseBody
//	public Administrator findById(Long id) {
//		System.out.println(administratorManager.findById(id));
//		return administratorManager.findById(id);
//	}
	
	
	@RequestMapping(method = RequestMethod.GET, value = "/all.html")
//	@RequestMapping("/administrator")
//	@RequestMapping(method = RequestMethod.GET, value = "/all.json")
//	@RequestMapping(method = RequestMethod.GET, value = "/administrator")
	@ResponseBody
	public String getAdministratorAll() {
		return JSON.toJSONString(administratorManager.findAll());
	}
	
	@RequestMapping(method = RequestMethod.GET, value = "all")
	@ResponseBody
	public String getAll() {
		return JSON.toJSONString(administratorManager.findAll());
	}
	
	
	
//	@DeleteMapping("/deletebyid/{id}")
	@GetMapping("/deletebyid/{id}")
	public Boolean deleteById(@PathVariable("id") Long id) {
//		Optional<CourseInformation> courseInformation = this.manager.findByCourseId(id);
		Boolean result = this.manager.deleteById(id);
		return result;
	}
	
	@GetMapping("/findById/{id}")
	public Administrator getAdministratorById(@PathVariable("id") Long id) {
		Administrator Ar=this.manager.getAdministratorById(id);
//		System.out.println(Ar.getId()+Ar.getName());
		return Ar;
	}
	

//	@GetMapping("/save/{name}")
//	public Administrator save(@PathVariable("name") String Name) {
//		Administrator administrator= new Administrator();
//		administrator.setName(Name);
//		Administrator result = administratorManager.save(administrator);
//		return result ;
//	}
//	
//	@GetMapping("/updata/{id}")
//	public Administrator updata(@PathVariable("id") Long id) {
//		Optional<Administrator> administrator = this.manager.findBycourseId(id);
//		Administrator administrator_s = administrator.get();
//		administrator_s.setName("zhangsan");
//		Administrator result = this.manager.save(administrator_s);
//		return result;
//	}
	
}
